﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.Mvc.Ajax;
using TaobaoERP.BusinessTaobao.TaobaoAPI;
using TaobaoERP.BusinessServices;
using TaobaoERP.Entity;
using TaobaoERP.Core.Common;

namespace TaobaoERP.Controllers
{
    public class SettingsController : Controller
    {
        SettingsService service = new SettingsService();
        public ActionResult Index()
        {
            // Add action logic here
            throw new NotImplementedException();
        }

        public ActionResult ItemCats(int? id)
        {
            // Add action logic here
            ViewData["totail"] = service.CountItemcasts(id ?? 0);
            if (ViewData["totail"].ToString() == "0")
            {
                if (string.IsNullOrEmpty(Utils.GetCookies("sessionid")))
                    Utils.SetCookies("sessionid", Session.SessionID);
                service.UpdateItemcats(Utils.GetCookies("sessionid"), id);
            }
            //int PageIndex = Page ?? 0;
            //List<ItemCat> list =
            ViewData["totail"] = service.CountItemcasts(id ?? 0);
            ViewData["ParentID"] = id ?? 0;
            return View();
        }
        public JsonResult ListItemCats(int? Page,int? id)
        {
            // Add action logic here
            //service.UpdateItemcats(Request.Cookies["sessionid"].Value);
            int PageIndex = Page ?? 0;
            int Parentid = id ?? 0;
            List<ItemCat> list = service.ListItemcasts(10, PageIndex, Parentid);
            //ViewData["list"] = list;
            return Json(list);
            
        }
        
    }
}
